package com.edu.utils;

import com.ruoyi.common.core.domain.model.AppLoginUser;

/**
 * 用户上下文
 */
public class UserContextUtil {

  private static final ThreadLocal<AppLoginUser> THREAD_LOCAL = new ThreadLocal<>();

  public static AppLoginUser currentUser() {
    AppLoginUser user = THREAD_LOCAL.get();
    if (user != null) {
      return user;
    }
    user = new AppLoginUser();
    return user;
  }

  public static void setUser(AppLoginUser user) {
    THREAD_LOCAL.set(user);
  }

  public static void clean() {
    THREAD_LOCAL.remove();
  }

}
